﻿using System;
using System.Windows;
using System.Windows.Navigation;
using EzDesk.DesktopClient.PopupModule.ViewContract;
using EzDesk.DesktopClient.PopupModule.ViewModel;
using EzDesk.Generic;
using EzDesk.Generic.WPF;
using EzDesk.MVVMBase;

namespace EzDesk.DesktopClient.PopupModule.View
{
    /// <summary>
    /// Interaction logic for NotificationPopupView.xaml
    /// </summary>
    public partial class NotificationPopupView : WindowExtenBase, INotificationPopupView
    {
        public NotificationPopupView()
        {
            InitializeComponent();
            InitState();
            SizeChanged += Resize;
        }

        private void Resize(object sender, SizeChangedEventArgs e)
        {
            Height = TitlePanel.ActualHeight +
                          BodyPanel.DesiredSize.Height + 10;
        }

        private void InitState()
        {
            ShowInTaskbar = false;
        }

        protected void CloseBtn_Click(object sender, RoutedEventArgs e)
        {
            CloseNotificationView();
        }

        private void ContentControl_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            //OnNavigate.ExecuteMethod(null, "http://localhost:2604/Test.aspx");
            OnNavigate.ExecuteMethod(null, e.Uri.AbsoluteUri);
        }

        public event EventHandler<GenericEventArg<string>> OnNavigate;

        public void CloseNotificationView()
        {
            this.OnWindowClosing.ExecuteMethod(null, null);
            this.CloseCurrentWindow();
            this.ViewModel = null;
        }

        public event EventHandler OnWindowClosing;

        public new INotificationPopupViewModel ViewModel
        {
            get { return DataContext as INotificationPopupViewModel; }
            set { DataContext = value; }
        }
    }
}
